﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing.util {
    import flash.utils.*;
    import org.aswing.event.*;

    public class Timer extends AbstractImpulser implements Impulser {

        private var intervalID:int;

        public function Timer(_arg1:uint, _arg2:Boolean=true){
            super(_arg1, _arg2);
            this.intervalID = 0;
        }
        override public function start():void{
            isInitalFire = true;
            clearInterval(this.intervalID);
            this.intervalID = setInterval(this.fireActionPerformed, getInitialDelay());
        }
        override public function isRunning():Boolean{
            return (!((this.intervalID == 0)));
        }
        override public function stop():void{
            clearInterval(this.intervalID);
            this.intervalID = 0;
        }
        override public function restart():void{
            this.stop();
            this.start();
        }
        private function fireActionPerformed():void{
            if (isInitalFire){
                isInitalFire = false;
                if (repeats){
                    clearInterval(this.intervalID);
                    this.intervalID = setInterval(this.fireActionPerformed, getDelay());
                } else {
                    this.stop();
                };
            };
            dispatchEvent(new AWEvent(AWEvent.ACT));
        }

    }
}//package org.aswing.util 
